<template>
    <div>
        <van-row style="margin-top: 1rem;"> 
            <van-col span="2" >
                <van-icon name="arrow-left" @click="exit" />
            </van-col>
        </van-row>
        <p>新增地址</p>
        <van-row>
            <van-col span="24">
                <van-address-edit
                    :area-list="areaList"
                    show-postal
                    show-set-default
                    show-search-result
                    :area-columns-placeholder="['请选择', '请选择', '请选择']"
                    @save="onSave"
    
                    />
                    
            </van-col>
        </van-row>
    </div>
</template>

<script>
    import { addUserAddress } from '@/api/index'
    import { Toast } from 'vant';
    import { areaList } from '@vant/area-data';
    export default {
        data() {
            return {
                areaList,
                searchResult: [],
                null:{},
            };
        },
  methods: {
    // 返回上一级
    exit(){
          this.$router.push('/address')
    },
    onSave(content) {

      console.log(content);
      content['username']=localStorage.getItem('username')

      addUserAddress(content).then(res=>{
        console.log(res.data.data);
        if(res.data.status){
          Toast("添加地址成功")
          this.$router.push("/address")
        }
        else 
          Toast("添加地址失败,可能已经有默认地址了")
      })
    },
    
    // onChangeDetail(val) {
    //   console.log(val);
    // },
  },
};

</script>